//
// Created by 11510 on 2024/7/4.
//
#include <iostream>
#include <thread>
#include <mutex>

using namespace std;

int cnt = 0;
mutex mtx;

class MutexLockGuard {
public:
    MutexLockGuard(mutex &mtx) : _mutex(mtx) {
        _mutex.lock();
    }

    ~MutexLockGuard() {
        _mutex.unlock();
        printf("~Lock\n");
    }

private:
    mutex &_mutex;
};

void threadFunc(void) {
    for (size_t idx = 0; idx != 10000; ++idx) {
        {
            lock_guard<mutex> lg(mtx);
            cnt++;
        }
    }
}


int main() {
    thread th1(threadFunc);
    thread th2(threadFunc);
    th1.join();
    th2.join();

    cout << cnt << endl;
    return 0;
}
